package com.ankicoo.common.controller;

import com.ankicoo.common.entity.CommCityPO;
import com.ankicoo.common.mapper.CommCityMapper;
import com.ankicoo.common.model.CityList;
import com.ankicoo.common.response.ResponseBody;
import com.ankicoo.common.service.CommCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Description: 通用城市处理
 *
 * @author : QCYANG
 * @date : 2021/11/23 17:06
 */
@RestController
@RequestMapping("/city")
public class CommCityController {
    @Autowired
    private CommCityService cityService;

    /**
     * description: 获取一级行业信息
     * author: QCYANG
     * create_time: 2020/9/24 8:59
     */
    @GetMapping("/getIndustryListByLevel/{level}")
    public ResponseBody<List<CommCityPO>> getTopIndustryList(@PathVariable Integer level){
        List<CommCityPO> cityListOfLevel = cityService.findCityListByLevel(level);
        return ResponseBody.createBySuccess(cityListOfLevel);
    }

    /**
     * description : 查找当前层级城市信息 附带全量子城市信息 （不建议常用 查询较慢。。非常慢）
     * @param level 层级
     * @return  城市信息全量列表
     * @author : QCYANG
     * @date : 2021/11/25 17:31
     */
    @GetMapping("/getWholeIndustryListByLevel/{level}")
    public ResponseBody<List<CityList>> getWholeIndustryListByLevel(@PathVariable Integer level){
        List<CityList> fullCityListByLevel = cityService.findFullCityListByLevel(level);
        return ResponseBody.createBySuccess(fullCityListByLevel);
    }

    /**
     * description : 通过id查找子地址信息列表
     * @param cityId 地址编号
     * @return  子地址列表
     * @author : QCYANG
     * @date : 2021/11/25 17:43
     */
    @GetMapping("/getSubCityListById/{cityId}")
    public ResponseBody<List<CommCityPO>> getSubCityListById(@PathVariable String cityId){
        List<CommCityPO> fullCityListByLevel = cityService.findSubCityListById(cityId);
        return ResponseBody.createBySuccess(fullCityListByLevel);
    }
}
